<template>
   <div id="login">
		<div class="vali_list login_list">
			<h4>登录</h4>
			<ul>
				<li><img src="../../../public/images/reg_logo.png"/></li>
				<li>
					<el-input size="large" placeholder="请输入您的手机号" v-model="message.infoDetail.username"></el-input>
				</li>
				<li>
					<el-input size="large" type="password" placeholder="请输入您的密码" v-model="message.infoDetail.password"></el-input>
				</li>
				<li >
					<el-button type="primary" size="large" @click="loginFor">下一步</el-button>
					<a href="forgetpwd.html">忘记密码？</a>
				</li>
			</ul>
			<p class="heaven">没有账号？<router-link to="/form/register">立即注册！</router-link></p>
		</div>
   </div>
</template>

<script>
    import {Checks} from 'src/public/js/Verification';
    import qs from 'qs';
    export default {
        name:'login',

		data() {
            return {
                message:{
                    infoDetail:{
                        username:'',
                        password:''
                    }
                }
			}
		},
		computed:{
            userInfo() {
             //   return this.$store.state.Check.userInfo;
            }
		},
		methods:{
            loginFor() {
            	const _this = this;
				this.axios.post(_this.$store.state.Check.url + '/login',qs.stringify({
                        username:_this.message.infoDetail.username,
                        password:_this.message.infoDetail.password
                })).then(resultData => {
                    const data = resultData.data;
                    if (data.status == 200) {
                        this.$notify({
                            title: '成功',
                            message: '登录成功',
                            type: 'success'
                        });
                      	_this.$store.state.Check.slug = data.data.slug;
                      	localStorage.slug = data.data.slug;
                      	_this.$router.push('/mine/personal');
                    } else {
                        this.$notify({
                            title: '警告',
                            message: data.msg,
                            type: 'warning'
                        });
                    }
                }).catch(err => {
                    this.$notify({
                        title: '警告',
                        message: '网络出错了~再试试吧~',
                        type: 'warning'
                    });
                });
            }
		},

        created() {
            // console.log('test');
            // console.log(this.$route.query.type); //值为我们传过来的type
            // console.log(this.$store.state.Check.type); //先查看store里现在有什么,type应该是为0的
            if (this.$store.state.Check.type > 1) {
                this.$store.dispatch('renameType');
            }
            const type = this.$route.query.type ? this.$route.query.type : this.$store.state.Check.type;
            if (type == 1) {
                this.$message({
                    message: '您需要先进行登陆！',
                    type: 'warning'
                });
                this.$store.dispatch('changeType',1);
            } else {
                this.$message({
                    message: '欢迎登陆！',
                    type: 'success'
                });
            }
        }
    }
</script>

<style scoped lang="less" rel="stylesheet/less" type="text/css">
	@import '../../../public/css/variable.less';
	.regist{ height: 780px; }
	.regist_wrap{
	    width: 450px;
	    margin: 60px auto 0;
	    button{ 
	    	width: 100%; 
	    	border: 0;
	    	box-shadow: 2px 2px 2px @cgolden;
	        background: -webkit-linear-gradient(#d8b26a, #cca965);
	        &:hover{ background: #cca965; }
	    }
	    ul{
	        width: 320px;
	        li{
	            .cf();
	            a{
	                .fonts(12px);
	                color: #0b69aa;
	                float: right;
	            }
	        }
	    }
	}

	.login_list{
	    h4{
	        margin: 0 40px 15px;
	    }
	}
</style>